//
//  GrantReviewContViewController.m
//  DistributorAB
//
//  Created by 主事丫环 on 2019/9/26.
//  Copyright © 2019 主事丫环. All rights reserved.
//

#import "GrantReviewContViewController.h"
#import "GrantReviewConTableViewCell.h"

#import "GrantReviewDetailViewController.h" //查看详情

@interface GrantReviewContViewController ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic, strong) UITableView *mytableView;
@property (nonatomic, strong) UIScrollView *scrollView;
@property (nonatomic, strong) NSMutableArray *mydateSource;
@property (nonatomic, strong) NSMutableArray *modelArr;

@end

@implementation GrantReviewContViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"补助金审核";
    [self.leftbutton setImage:imgname(@"left_icon") forState:(UIControlStateNormal)];
    self.view.backgroundColor = [UIColor colorWithHexString:@"#F2F2F2"];
    
    self.mydateSource = [NSMutableArray arrayWithCapacity:1];
    self.modelArr = [NSMutableArray arrayWithCapacity:1];
    
    [self showdetaile];
    
    [self requeset];
    // Do any additional setup after loading the view.
}

-(void)showdetaile {
    
    [self.view addSubview:self.scrollView];
    
    _mytableView = [[UITableView alloc] init];
    _mytableView.frame = CGRectMake(0, 10, KWIDTH, KHEIGHT - kNaviHeight -50);
    _mytableView.delegate = self;
    _mytableView.dataSource = self;
    _mytableView.estimatedRowHeight = 90;
    _mytableView.rowHeight = UITableViewAutomaticDimension;
    _mytableView.tableFooterView = [UIView new];
    [_mytableView registerClass:[GrantReviewConTableViewCell class] forCellReuseIdentifier:@"GrantReviewConTableViewCell"];
    //_mytableView.backgroundColor = [UIColor clearColor];
    _mytableView.backgroundColor = [UIColor colorWithHexString:@"#F2F2F2"];
    adjustInset(_mytableView);
    [_mytableView reloadData];
    [_scrollView addSubview:_mytableView];
}

-(void)requeset{
    kWeakSelf;
    NSMutableDictionary *param = [NSMutableDictionary dictionaryWithCapacity:1];
    NSInteger ind = [_type integerValue];
    
    ind-=1;
    if (ind >1) {
        ind +=1;
    }
    NSString *stt  = [NSString stringWithFormat:@"%ld",ind];
    if (ind == -1) {
        stt = @"";
    }
    
    //补助金审核状态(1已提交2已结束 全部传空)
    param[@"state"] = stt;
    [weakSelf.mydateSource removeAllObjects];
    [NetWorkTool POST:BZJgrantsList param:param success:^(id dic) {
        
        //self.mydateSource = [CSmaintenanceListModel mj_objectArrayWithKeyValuesArray:dic[@"data"]];

        [self.mytableView reloadData];
        [self.mytableView.mj_header endRefreshing];
        
    } other:^(id dic) {
        ShowToastWithText(dic[@"msg"]);
        [weakSelf.mydateSource removeAllObjects];
        [self.mytableView reloadData];
        [self.mytableView.mj_header endRefreshing];
        
    } fail:^(NSError *error) {
        [weakSelf.mydateSource removeAllObjects];
        [self.mytableView reloadData];
        [self.mytableView.mj_header endRefreshing];
        
    } needUser:YES];
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    //return _modelArr.count;
    return 10;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 180;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 10;
}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
    return [UIView new];
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    return 0.01;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    return [UIView new];
}

- (nonnull UITableViewCell *)tableView:(nonnull UITableView *)tableView cellForRowAtIndexPath:(nonnull NSIndexPath *)indexPath {
    //定义Cell标识 每一个Cell对应一个自己的标识
    NSString *CellIdentitier = [NSString stringWithFormat:@"cell%ld%ld",indexPath.section, indexPath.row];
    
    //通过唯一标识创建Cell实例
    GrantReviewConTableViewCell *mycell = [tableView dequeueReusableCellWithIdentifier:CellIdentitier];
    //判断为空进行初始化  --(当拉动页面显示超过主页面内容的时候就会重用之前的cell,w而不会再次初始化)
    if (!mycell) {
        mycell = [[GrantReviewConTableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentitier];
    }
    self.mytableView.separatorStyle = UITableViewCellEditingStyleNone;//不显示分割线
    
    return mycell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    GrantReviewDetailViewController *detail = [[GrantReviewDetailViewController alloc] init];
    
    [self.navigationController pushViewController:detail animated:YES];
}

-(UITableView *)myTableView{
    if (!_mytableView) {
        _mytableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, KWIDTH, KHEIGHT-kNaviHeight-49) style:(UITableViewStylePlain)];
        _mytableView.backgroundColor = [UIColor clearColor];
        _mytableView.delegate = self;
        _mytableView.dataSource = self;
        _mytableView.estimatedRowHeight = 90;
        _mytableView.rowHeight = UITableViewAutomaticDimension;
        _mytableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        _mytableView.tableFooterView = [UIView new];
        //[_mytableView registerNib:[UINib nibWithNibName:@"DISAcompllainListTableViewCell" bundle:nil] forCellReuseIdentifier:@"DISAcompllainListTableViewCell"];
        [_mytableView registerClass:[GrantReviewConTableViewCell class] forCellReuseIdentifier:@"GrantReviewConTableViewCell"];
        adjustInset(_mytableView);
        
        kWeakSelf;
        weakSelf.myTableView.placeHolderView = [[KKTableViewNoDataView alloc]initWithFrame:_mytableView.bounds image:imgname(@"tableviewPlaseholder") viewClick:^{
            [weakSelf.myTableView.mj_header beginRefreshing];
        }];
        
        self.myTableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
            //            [self requeset];//请求数据
            
        }];
        [self.scrollView addSubview:_mytableView];
    }
    return _mytableView;
}

- (UIScrollView *)scrollView {
    if (!_scrollView) {
        _scrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, KWIDTH, KHEIGHT)];
        //_scrollView.backgroundColor = [UIColor colorWithHexString:@"#F2F2F2"];
        _scrollView.backgroundColor = [UIColor whiteColor];
        _scrollView.delegate = self;
        _scrollView.contentSize = CGSizeMake(KWIDTH, 100);
        
        adjustInset(_scrollView);
    }
    return _scrollView;
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
